package cn.yerly.sakura.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.data.elasticsearch.annotations.Document;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import java.util.Objects;

/**
 * A UserAddress.
 */
@Entity
@Table(name = "USERADDRESS")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName="useraddress")
public class UserAddress implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Size(max = 128)
    @Column(name = "detail", length = 128)
    private String detail;

    @Size(max = 20)
    @Column(name = "zip", length = 20)
    private String zip;

    @Column(name = "receiver")
    private String receiver;

    @Size(max = 20)
    @Column(name = "mobile", length = 20)
    private String mobile;

    @Size(max = 20)
    @Column(name = "tel", length = 20)
    private String tel;

    @Column(name = "dft")
    private Boolean dft;

    @Column(name = "disabled")
    private Boolean disabled;

    @ManyToOne
    private User user;

    @OneToOne
    private Location location;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

    public String getReceiver() {
        return receiver;
    }

    public void setReceiver(String receiver) {
        this.receiver = receiver;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public Boolean getDft() {
        return dft;
    }

    public void setDft(Boolean dft) {
        this.dft = dft;
    }

    public Boolean getDisabled() {
        return disabled;
    }

    public void setDisabled(Boolean disabled) {
        this.disabled = disabled;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Location getLocation() {
        return location;
    }

    public void setLocation(Location location) {
        this.location = location;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        UserAddress userAddress = (UserAddress) o;

        if ( ! Objects.equals(id, userAddress.id)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }

    @Override
    public String toString() {
        return "UserAddress{" +
                "id=" + id +
                ", detail='" + detail + "'" +
                ", zip='" + zip + "'" +
                ", receiver='" + receiver + "'" +
                ", mobile='" + mobile + "'" +
                ", tel='" + tel + "'" +
                ", dft='" + dft + "'" +
                ", disabled='" + disabled + "'" +
                '}';
    }
}
